package com.wulin.wucut.service.impl;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject;
import com.wulin.wucut.domain.entity.draft.meta.info.DraftMetaInfo;
import com.wulin.wucut.properties.JianYinDraftProperties;
import com.wulin.wucut.service.FileService;
import com.wulin.wucut.utils.JianYinUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class FileServiceImpl implements FileService {
    private final JianYinDraftProperties jianYinDraftProperties;
    
    
    @Override
    public DraftMetaInfo getDraftMetaInfo() {
        String name = jianYinDraftProperties.getName();
        String directory = jianYinDraftProperties.getDirectory();
        String metaInfoPath = JianYinUtil.getDraftMetaInfoPath(directory, name);
        String metaInfo = FileUtil.readUtf8String(metaInfoPath);
        return JSONObject.parseObject(metaInfo, DraftMetaInfo.class);
    }
    
    
    
}
